const Sequelize = require('sequelize')
const { sequelize } = require('../init')
const moment = require('moment')

const user = sequelize.define('user', {
  id: {
    type: Sequelize.INTEGER,
    allowNull: false,
    primaryKey: true,
    autoIncrement: true
  },
  uid: {
    type: Sequelize.STRING(32),
    allowNull: false
  },
  nickname: {
    type: Sequelize.STRING(32),
    allowNull: false
  },
  avatar: {
    type: Sequelize.TEXT,
    allowNull: true
  },
  province: {
    type: Sequelize.STRING(32),
    allowNull: true
  },
  city: {
    type: Sequelize.STRING(32),
    allowNull: true
  },
  sex: {
    type: Sequelize.STRING(32),
    allowNull: true
  },
  // 违规次数
  foul_num: {
    type: Sequelize.STRING(32),
    allowNull: true
  },
  // 禁用到期时间
  disable_time: {
    type: Sequelize.STRING(32),
    allowNull: true
  },
  createdAt: {
    type: Sequelize.DATE,
    get() {
        return moment(this.getDataValue('createdAt')).format('YYYY-MM-DD HH:mm:ss');
    }
  },
  updatedAt: {
    type: Sequelize.DATE,
    get() {
        return moment(this.getDataValue('updatedAt')).format('YYYY-MM-DD HH:mm:ss');
    }
  }
}, {
    // 如果为 true 则表的名称和 model 相同，即 user
    // 为 false MySQL创建的表名称会是复数 users
    // 如果指定的表名称本就是复数形式则不变
    freezeTableName: true
})

module.exports = user